<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../assets/mock/mock-min.js"></script>
    <script>
        // mock 方法的模板定义规则，其实就是 Mock.Random 中对应的数据类型函数的另外一种调用规则

        // String 的模块规则
        // 1、长度随机  [ min-max ] 在min和max之间进行随意范围生成
        console.log(Mock.mock({
            "str|1-10": "A"
        }))
        // 2、生成固定长度字符串  [ count ] 在固定范围内生成数据
        console.log(Mock.mock({
            str: "ABCDEFG",
            "info:|10": "☆"
        }))

        // Number 的模板规则
        // 1、数值累加  [ +数值 ] 数值累计计数，需要注意程序构建时用于累加计数的模板值，必须属于全局共享状态 
        let numTemp1 = {
            "id|+1": 202
        }
        console.log(Mock.mock(numTemp1))
        console.log(Mock.mock(numTemp1))
        console.log(Mock.mock(numTemp1))
        console.log(Mock.mock(numTemp1))

        let numTemp2 = {
            "id|+5": 202
        }
        console.log(Mock.mock(numTemp2))
        console.log(Mock.mock(numTemp2))
        console.log(Mock.mock(numTemp2))

        // 2、带小数生成 [ min-max.dmin-dmax ]
        console.log(Mock.mock({
            "num|1-100.0-5": 0
        }))

        // 取值小数时 . 后续的数值在满足小数位数的情况下会作为默认小数值出现
        console.log(Mock.mock({
            "num|1-100.0-5": 0.12
        }))

        // 取值小数时 . 后续只有一个数值，属于位数限定
        console.log(Mock.mock({
            "num|1-100.3": 0
        }))

        // Boolean 的模板规则
        // 1、50% boolean值出现几率  [ 属性名|1 ]
        console.log(Mock.mock({
            "boolean|1": true
        }))
        // 2、手动设置出现几率 [ 属性|min-max ]   min/(min+max) , 取值出现的几率是多少
        console.log(Mock.mock({
            "boolean|1-9": true
        }))

        // Object 的对象取值
        // 在枚举列表中加载对应数量的数据
        console.log(Mock.mock({
            "object|2": {
                "310000": "上海市",
                "320000": "江苏省",
                "330000": "浙江省",
                "340000": "安徽省"
            }
        }))
        console.log(Mock.mock({
            "object|2-4": {
                "310000": "上海市",
                "320000": "江苏省",
                "330000": "浙江省",
                "340000": "安徽省"
            }
        }))

        // Array 的数值取值
        // 1、无序枚举定义和有序枚举定义 [ |1 ] 或者 [ |+数值 ] => 属性的类型取决于枚举结果类型 => 该规则不是用于生成数组的
        let modelTemp = {
            "modelA|1": [
                "AMD", "CMD", "UMD", false
            ],
            "modelB|+1": [
                "AMD", "CMD", "UMD", false
            ]
        }
        console.log(Mock.mock(modelTemp))
        console.log(Mock.mock(modelTemp))
        console.log(Mock.mock(modelTemp))
        console.log(Mock.mock(modelTemp))
        console.log(Mock.mock(modelTemp))

        // 2、数组生成 [ min-max ]  或者 [ count ] count>1
        console.log(Mock.mock({
            "arr|2": [
                "AMD", "CMD", "UMD"
            ]
        })) 
    </script>
</head>

<body>

</body>

</html>